﻿/****************************** Module Header ******************************\
 * Module Name:  FormsSkinHelper.cs
 * Module Version:  1.0.0 (2012-11-9)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to process the FormsSkinHelper.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UCL.Forms
{
    public class FormsSkinHelper:SoSkinHelper
    {
        public IFormsSkin Skin { get; set; }

        public FormsSkinHelper(IFormsSkin skin)
        {
            Skin = skin;
        }

        public void SetSkin(Control.ControlCollection cc)
        {
            foreach (Control c1 in cc)
            {
                bool a = SetSkinFunc(c1);
                if (c1.Controls.Count > 0 && a) SetSkin(c1.Controls);
            }
        }
        /// <summary>
        /// 返回是否是一个标准容器
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private bool SetSkinFunc(Control c)
        {
            if (c.GetType() == typeof(DataGridView))
            {
                DataGridView dgv=c as DataGridView;
                dgv.AutoGenerateColumns = false;
                dgv.SelectionMode = Skin.SelectionMode;
                dgv.BackgroundColor = Skin.DataGridViewBgColor;
                dgv.BorderStyle = Skin.DataGridViewBorderStyle;
                dgv.SetColumnHeadersStyle(Skin.DataGridViewColumnHeadersBgColor);
                if (Skin.AutoSetDataGridViewRowHeaders) dgv.SetRowHeaderIndex();
                return false;
            }
            if (c.GetType() == typeof(TabControl))
            {
                ((TabControl)c).SetTabBgColor(Skin.TabPageNormalBgColor, Skin.TagPageSelectedBgColor, Skin.TagPageFontColor);
                return true;
            }
            if (c.GetType() == typeof(Button))
            {
                // Button btn = (Button)c;
                //btn.BackColor = Skin.ButtonBgColor;
                //btn.ForeColor = Skin.ButtonForeColor;
                //btn.FlatStyle = FlatStyle.Flat;
                return false;
            }
            //if (c.GetType() == typeof(SplitContainer) || c.GetType() == typeof(Panel) || c.GetType() == typeof(FlowLayoutPanel)) c.BackColor = System.Drawing.Color.Transparent;
            return true;
        }
    }
}
